using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Windows.Forms;
using Kupper;
using Kupper.Settings;
using ff14bot;
using ff14bot.Behavior;
using ff14bot.Enums;
using ff14bot.Helpers;
using ff14bot.Managers;
using ff14bot.Navigation;
using ff14bot.Objects;
using TreeSharp;
using Action = TreeSharp.Action;
using System.ComponentModel;
using System.Globalization;
using System.Configuration;

namespace Kupper.Settings
{
    internal class ArcherSettings : KupperSettings
    {

        public class CsvConverter : TypeConverter
        {
            // Overrides the ConvertTo method of TypeConverter.
            public override object ConvertTo(ITypeDescriptorContext context,
               CultureInfo culture, object value, Type destinationType)
            {
                List<String> v = value as List<String>;
                if (destinationType == typeof(string))
                {
                    return String.Join(",", v.ToArray());
                }
                return base.ConvertTo(context, culture, value, destinationType);
            }
        }
		
        public ArcherSettings(string filename = "Archer-KupperSettings"): base(filename)
        {
        }

		//Timers
		[Setting]
		[Category("Timers")]
        [DefaultValue(6000)]
		[Description("How much opener buff time remaining before attempting to refresh DOTs")]
		[DisplayName("DOT Refresh")]
        public int DOTRefresh { get; set; }	
		
		[Setting]
		[Category("Timers")]
		[DefaultValue(1000)]
		[Description("Time in ms to clip DOTs")]
		[DisplayName("DOT Clip Time")]
		public int DOTClip { get; set; }
		
		[Setting]
		[Category("Timers")]
		[DefaultValue(1000)]
		[Description("Time in ms to clip Straight Shot")]
		[DisplayName("SS Clip Time")]
		public int SSClip { get; set; }
		
		
		//Limits
		[Setting]
		[Category("Limits")]
        [DefaultValue(4)]
		[Description("If more than this number of targets are in range, use AOEs.")]
		[DisplayName("AOE Targets")]
        public int AOELimit { get; set; }
		
		[Setting]
		[Category("Limits")]
        [DefaultValue(400)]
		[Description("Routine will stop using AOE when TP is below this amount")]
		[DisplayName("AOE TP Limit")]
        public int AOETPLimit { get; set; }		

		[Setting]
		[Category("Limits")]
        [DefaultValue(0)]
		[Description("DOTs will only be applied if the target's HP is above this value")]
		[DisplayName("DOT HP Limit")]
        public int DOTLimit { get; set; }
		
		[Setting]
        [Category("Limits")]
        [DefaultValue(0)]
        [Description("Buffs will only be used if the target's HP is above this value")]
		[DisplayName("Buff HP Limit")]
        public int BuffHPLimit { get; set; }
		
		[Setting]
        [DefaultValue(54)]
        [Category("Limits")]
        [DisplayName("Invigorate TP %")]
        public int UseInvigorateTP { get; set; }
		
		[Setting]
        [DefaultValue(40)]
        [Category("Limits")]
        [DisplayName("Second Wind HP %")]
        public int UseSecondWindHP { get; set; }
		
		[Setting]
        [DefaultValue(40)]
        [Category("Limits")]
        [DisplayName("Featherfoot HP %")]
        public int UseFeatherfootHP { get; set; }
		
		[Setting]
        [DefaultValue(40)]
        [Category("Limits")]
        [DisplayName("Keen Flurry HP %")]
        public int UseKeenFlurryHP { get; set; }
		
		//Abilities
		[Setting]
        [Category("Abilities")]
        [DefaultValue(true)]
		[DisplayName("Flaming Arrow")]
        public bool UseFlamingArrow { get; set; }
		
		[Setting]
        [Category("Abilities")]
        [DefaultValue(false)]
		[DisplayName("Repelling Shot")]
        public bool UseRepellingShot { get; set; }
		
		[Setting]
        [Category("Abilities")]
        [DefaultValue(true)]
		[DisplayName("Blunt Arrow")]
        public bool UseBluntArrow { get; set; }
				
        [Setting]
        [Category("Abilities")]
        [DefaultValue(true)]
        [DisplayName("* Use Buffs *")]
        public bool UseBuffs { get; set; }
		
		[Setting]
        [Category("Abilities")]
        [DefaultValue(false)]
        [DisplayName("Dexterity Potions")]
        public bool UseBuffPotions { get; set; }
		
		[Setting]
        [Category("Abilities")]
        [DefaultValue(false)]
        [DisplayName("Poison Potions")]
        public bool UsePoisonPotions { get; set; }
		
        [Setting]
        [DefaultValue(true)]
        [Category("Abilities")]
        [DisplayName("Internal Release")]
        public bool UseInternalRelease { get; set; }

        [Setting]
        [DefaultValue(true)]
        [Category("Abilities")]
        [DisplayName("Raging Strikes")]
        public bool UseRagingStrikes { get; set; }

        [Setting]
        [DefaultValue(true)]
        [Category("Abilities")]
        [DisplayName("Hawk's Eye")]
        public bool UseHawksEye { get; set; }

        [Setting]
        [DefaultValue(true)]
        [Category("Abilities")]
        [DisplayName("Barrage")]
        public bool UseBarrage { get; set; }
        
		[Setting]
        [DefaultValue(true)]
        [Category("Abilities")]
        [DisplayName("Quelling Strikes")]
        public bool UseQuellingStrikes { get; set; }
        
		[Setting]
        [DefaultValue(true)]
        [Category("Abilities")]
        [DisplayName("Blood for Blood")]
        public bool UseBloodForBlood { get; set; }		
		
		[Setting]
        [DefaultValue(false)]
        [Category("Abilities")]
        [DisplayName("Silence")]
        public bool UseInterrupt { get; set; }
		
		//Rotation
		[Setting]
		[Category("Rotation")]
        [DefaultValue(false)]
		[Description("Will change the opening cooldown rotation and refresh DOTs before they fall off.")]
		[DisplayName("Opener")]
        public bool UseOpener { get; set; }		
				
		[Setting]
		[Category("Rotation")]
        [DefaultValue(false)]
		[Description("Will delay using Blood for Blood so that it aligns with Barrage if reasonable.")]
		[DisplayName("Align B4B")]
        public bool AlignB4B { get; set; }	

		[Setting]
        [Category("Rotation")]
        [DefaultValue(false)]
		[Description("Will only use buff potions during an opening rotation if true.")]
        [DisplayName("Opener Pot Only")]
        public bool UseOpenerPotion { get; set; }
		
		[Setting]
		[Category("Rotation")]
        [DefaultValue(false)]
		[Description("If true, routine will automatically use AOE abilities if they will hit at least the number of specified targets.")]
		[DisplayName("Automatic AOE")]
        public bool AutoAOE { get; set; }
		
		[Setting]
		[Category("Rotation")]
        [DefaultValue(false)]
		[Description("If true, routine will use AOE regardless of the number of targets.")]
		[DisplayName("AOE Override")]
        public bool AOEOverride { get; set; }
		
		//Lists
		private List<String> _interrupt;
				
		[Description("Spells which should be interrupted.")]
        [Editor(@"System.Windows.Forms.Design.StringCollectionEditor," +
            "System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
           typeof(System.Drawing.Design.UITypeEditor))]
		[TypeConverter(typeof(CsvConverter))]
        [Category("Lists")]
        [DisplayName("Spells to Interrupt")]
        public List<String> Interrupt
        {
            get
            {
                if (_interrupt == null)
                    _interrupt = new List<String>();
                return _interrupt;
            }
        }
		
		private List<String> _DontAOE;
				
		[Description("Enemies to not use AOE against")]
        [Editor(@"System.Windows.Forms.Design.StringCollectionEditor," + 
			"System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
			typeof(System.Drawing.Design.UITypeEditor))]
		[TypeConverter(typeof(CsvConverter))]
        [Category("Lists")]
        [DisplayName("Don't AOE Targets")]
        
		public List<String> DontAOE
        {
            get
            {
                if (_DontAOE == null)
                    _DontAOE = new List<String>();
                return _DontAOE;
            }
        }
		
		private List<String> _DontVB;
				
		[Description("Enemies to not use Venomous Bite against")]
        [Editor(@"System.Windows.Forms.Design.StringCollectionEditor," + 
			"System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
			typeof(System.Drawing.Design.UITypeEditor))]
		[TypeConverter(typeof(CsvConverter))]
        [Category("Lists")]
        [DisplayName("Don't VB Targets")]
        public List<String> DontVB
        {
            get
            {
                if (_DontVB == null)
                    _DontVB = new List<String>();
                return _DontVB;
            }
        }

		private List<String> _DontDOT;
				
		[Description("Enemies to not use DOTs against")]
        [Editor(@"System.Windows.Forms.Design.StringCollectionEditor," + 
			"System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
			typeof(System.Drawing.Design.UITypeEditor))]
		[TypeConverter(typeof(CsvConverter))]
        [Category("Lists")]
        [DisplayName("Don't DOT Targets")]
        public List<String> DontDOT
        {
            get
            {
                if (_DontDOT == null)
                    _DontDOT = new List<String>();
                return _DontDOT;
            }
        }
		
		//Songs

		[Setting]
		[Category("Songs")]
        [DefaultValue(false)]
		[Description("Will use swiftsong outside of combat if possible.")]
		[DisplayName("Swiftsong OOC")]
        public bool UseSwiftsong { get; set; }
		
		[Setting]
		[Category("Songs")]
        [DefaultValue(false)]
		[Description("If enabled, will allow swiftsong to override any current songs")]
		[DisplayName("Swiftsong Override")]
        public bool SwiftsongOverride { get; set; }		

		[Setting]
		[Category("Songs")]
        [DefaultValue(true)]
		[Description("If enabled Kupper will use buffs while damage down songs are playing.")]
		[DisplayName("Buffs During Songs")]
        public bool UseSongBuffs { get; set; }		
		
    }

    internal class BardSettings : ArcherSettings
    {
        public BardSettings(): base("Bard-KupperSettings")
        {
        }
    }

}